<template>
  <!-- <view class="login" :style="isShowRlsb?'padding: 7vh 52rpx 40rpx;':'padding: 11vh 52rpx 40rpx;'"> -->
  <view class="login">
    <view class="content">
      <view class="title">您 好！</view>
      <view class="subtitle">欢迎来到企教通教育培训系统</view>
      <view class="rl" v-if="isShowRlsb">
        <image src="@/static/images/login/rl.png"></image>
      </view>
      <view class="zhmm" v-else>
        <u--form labelPosition="left" :model="formData" ref="uForm">
          <u-form-item prop="account">
            <view class="inputItem account">
              <view class="icon">
                <!-- <u-icon name="account-fill" size="42rpx"></u-icon> -->
                <image src="@/static/images/login/account-icon.png"></image>
              </view>
              <u--input
                v-model="formData.account"
                fontSize="34rpx"
                color="#333333"
                placeholder="请输用户名"
                placeholderStyle="color: #9FA8BC;font-size: 34rpx;"
                cursorSpacing="0"
                border="none"
              ></u--input>
            </view>
          </u-form-item>
          <u-form-item prop="password">
            <view class="inputItem password">
              <view class="icon">
                <!-- <u-icon name="lock-fill" size="42rpx"></u-icon> -->
                <image src="@/static/images/login/password-icon.png"></image>
              </view>
              <u--input
                v-model="formData.password"
                fontSize="34rpx"
                color="#333333"
                placeholder="请输入密码"
                placeholderStyle="color: #9FA8BC;font-size: 34rpx;"
                cursorSpacing="0"
                password
                border="none"
              ></u--input>
            </view>
          </u-form-item>
          <!-- <view class="jzmm">记住密码</view> -->
          <view class="jzmm">
            <u-checkbox-group
              v-model="formData.isJzmm"
              size="30rpx"
              iconSize="30rpx"
              labelSize="26px"
              labelColor="#656667"
              activeColor="#1b63ff"
              @change="checkboxChange"
            >
              <u-checkbox v-for="(item, index) in ['记住密码']" :key="index" :label="item" :name="item"> </u-checkbox>
            </u-checkbox-group>
          </view>
        </u--form>
      </view>
      <template v-if="!isShowRlsb">
        <view class="btn rlsb" @click="loginClick">登录</view>
        <view class="btn zhdl" @click="isShowRlsb = true">人脸登录</view>
      </template>
      <template v-else>
        <view class="btn rlsb" @click="rlsbClick">人脸识别</view>
        <view class="btn zhdl" @click="isShowRlsb = false">账户登录</view>
      </template>
    </view>
    <view class="footer">登录代表你已经同意《用户协议》和《隐私权政策》</view>

    <!-- 人脸识别 -->
    <faceRecognition v-if="isShowFaceRecognition" @clone="isShowFaceRecognition = false"></faceRecognition>
  </view>
</template>

<script>
import { login } from "@/common/api/login/login.js";
import faceRecognition from "@/components/faceRecognition/faceRecognition.vue";
export default {
  components: {
    faceRecognition,
  },
  data() {
    return {
      isShowFaceRecognition: false,
      // 获取状态栏高度
      statusBarHeight: uni.getSystemInfoSync()["statusBarHeight"],
      isShowRlsb: false, //人脸识别登录
      formData: {
        isJzmm: [],

        account: "",
        password: "",
      },
      // rules: {
      //   account: {
      //     type: "string",
      //     required: true,
      //     message: "请填写账号",
      //     trigger: ["blur", "change"],
      //   },
      //   password: {
      //     type: "string",
      //     required: true,
      //     message: "请填写密码",
      //     trigger: ["blur", "change"],
      //   },
      // },
    };
  },
  onLoad() {
    let jzmmForm = this.$storage.get("jzmmForm") || undefined;
    if (jzmmForm) {
      this.formData = {
        ...jzmmForm,
      };
    }
  },
  methods: {
    checkboxChange(e) {
      if (Array.isArray(e) && e.length) {
        this.$storage.set("jzmmForm", {
          isJzmm: e,
          account: this.formData.account,
          password: this.formData.password,
        });
      } else {
        this.$storage.remove("jzmmForm");
      }
    },
    loginClick() {
      if (!this.formData.account) {
        return uni.showToast({
          title: "请输入账号",
          icon: "none",
        });
      }
      if (!this.formData.password) {
        return uni.showToast({
          title: "请输入密码",
          icon: "none",
        });
      }
      console.log(this.formData, "formData");
      delete this.formData.isJzmm;

      login(this.formData).then((res) => {
        if (res && res.code == 200 && res.data) {
          uni.setStorageSync("token", res.data.token);
          uni.showToast({
            title: "登录成功",
            icon: "none",
          });
          setTimeout(() => {
            // uni.switchTab({
            //   url: `/pages/index/index`,
            // });
            // uni.switchTab({
            //   url: `/pages/home/home`,
            // });
            uni.navigateTo({
              url: "/pages/huojia/huojia",
              // url: "/pages/personalInfo/personalInfo",
            });
          }, 300);
        }
      });
    },
    rlsbClick() {
      uni.showToast({
        title: "功能暂未开发",
        icon: "none",
      });
      return;
      this.isShowFaceRecognition = true;
    },
  },
};
</script>

<style lang="scss" scoped>
.login {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 100%;
  min-height: 100%;
  /* padding: calc(184rpx - 88rpx) 28rpx 40rpx; */
  /* padding: calc(10vh - 44rpx) 28rpx 40rpx; */
  /* padding: calc(10vh - 44rpx) 52rpx 40rpx; */
  /* padding: 183rpx 52rpx 40rpx; */
  padding: 11vh 52rpx 40rpx;
  background-image: url("~@/static/images/login/bj.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  color: #333333;
  font-weight: 500;
  line-height: 1;

  .content {
    .title {
      font-size: 82rpx;
      margin-bottom: 32rpx;
    }
    .subtitle {
      font-size: 32rpx;
    }
    .rl {
      display: flex;
      justify-content: center;
      width: 640rpx;
      height: 640rpx;
      padding: 30rpx;
      margin-top: 23rpx;
      margin-block: 21rpx;
      image {
        width: 100%;
        height: 100%;
      }
    }
    .zhmm {
      width: 100%;
      .inputItem {
        width: 100%;
        display: flex;
        align-items: center;
        padding: 32rpx 50rpx;
        background: #ffffff;
        border-radius: 100rpx;
        margin-bottom: 42rpx;
        .icon {
          display: flex;
          justify-content: center;
          align-items: center;
          width: 42rpx;
          height: 42rpx;
          margin-right: 32rpx;
          image {
            width: 100%;
            height: 100%;
          }
        }
      }
      .account {
        /* margin-top: 169rpx; */
        margin-top: 10vh;
      }
      .password {
        .icon {
          width: 34rpx;
          height: 40rpx;
        }
      }
      .jzmm {
        font-size: 26rpx;
        color: #656667;
        margin-left: 33rpx;
        /* margin-bottom: 114rpx; */
        margin-bottom: 7vh;
      }
    }

    .btn {
      padding: 36rpx 0;
      border-radius: 100rpx;
      font-weight: bold;
      font-size: 36rpx;
      color: #ffffff;
      text-align: center;
    }
    .rlsb {
      margin-bottom: 40rpx;
      background: linear-gradient(270deg, #1b63ff 0%, #6394fd 100%);
    }
    .zhdl {
      background: linear-gradient(270deg, #07a773 0%, #42d2a3 100%);
    }
  }
  .footer {
    margin-top: 40rpx;
    text-align: center;
    text-decoration: underline;
    font-size: 22rpx;
  }

  /deep/.u-form-item__body {
    padding: 0;
  }
  /deep/.u-checkbox-label--left uni-text {
    font-size: 26rpx !important;
    line-height: 1 !important;
  }
}
</style>
